function $(a) {
  return document.querySelector(a);
}
window.onload = function () {
  var tbody = document.querySelector("tbody");

  // 默认头像

  // 年龄框的数值
  function num(a, b, c) {
    for (let i = a; i <= b; i++) {
      let x;
      if (i < 10) {
        x = "0" + i;
      } else {
        x = i;
      }
      let option = `<option value ="${x}">${x}</option>`;
      c.insertAdjacentHTML("beforeend", option);
    }
  }
  num(1, 100, $(".age1"));
  num(1990, 2021, $(".year"));
  num(1, 12, $(".month"));
  num(1, 30, $(".date"));
  function str(a, b, c) {
    let s = "";
    if (c == null) {
      c = "无";
    }
    for (let i = a; i < b; i++) {
      s += c[i];
    }
    return s;
  }
  // 简介字数太多隐藏
  function str1(b) {
    let s = "";
    if (b.length >= 10) {
      for (let i = 0; i < 10; i++) {
        s += b[i];
      }
      s += "...";
    } else {
      for (let i = 0; i < b.length; i++) {
        s += b[i];
      }
    }
    return s;
  }
  //  全部数据
  $(".alllist").onclick = function () {
    $(".pageSize").style.display = "block";
    $(".pageSize1").style.display = "none";
    $(".nowpage-1").innerHTML = 1;
    $(".nowpage").value = $(".nowpage-1").innerHTML;
    $("#search").value = "";
    fenye(1, $(".pageSize").value);
  };
  // 点击显示数据每页几条
  $(".pageSize").onchange = function () {
    $(".nowpage-1").innerHTML = 1;
    $(".nowpage").value = $(".nowpage-1").innerHTML;
    fenye(1, $(".pageSize").value);
  };
  $(".pageSize1").onchange = function () {
    $(".nowpage-1").innerHTML = 1;
    $(".nowpage").value = $(".nowpage-1").innerHTML;
    searchdata(1, $(".pageSize1").value);
  };
  // 弹窗显示
  function popup(a, b, c) {
    a.addEventListener("click", function () {
      b.style.display = "block";
      $(".account").value = "";
      $(".password").value = "";
      $(".nickname").value = "";
    });
    c.addEventListener("click", function () {
      b.style.display = "none";
    });
  }
  // popup($(".add-all"),$(".add-box"),$(".back"));

  // 删除单个用户
  function delete_user(userId, b) {
    axios({
      method: "delete",
      url: "/user/deleteUser",
      params: {
        userId: userId,
      },
    })
      .then(function (data) {
        $(
          ".not"
        ).innerHTML = `<i class="fa fa-check" aria-hidden="true" style="color:green"></i>删除成功`;
        $(".not").style.display = "";
        setTimeout(() => {
          $(".not").style.display = "none";
        }, 1500);
        b($(".nowpage-1").innerHTML, $(".pageSize").value);
      })
      .catch((err) => {
        console.log(err);
      });
  }

  // // 渲染数据
  function fenye(a, b) {
    axios({
      method: "get",
      url: "/user/findAllUser",
      params: {
        pageNow: a,
        pageSize: b,
      },
    })
      .then(function (data) {
        $("tbody").innerHTML = "";
        $(".pageye").innerHTML = "";
        list(data, fenye);
      })
      .catch((err) => {
        console.log(err);
      });
  }
  fenye(1, 10);

  // 详情信息
  function usermessage(userId) {
    axios({
      method: "get",
      url: "/user/findUserById",
      params: {
        userId: userId,
      },
    })
      .then(function (data) {
        let list = data.data.data.object;
        console.log(data.data.data.object);
        //   $('.imghead').src= list.src=='未上传'?imgsrc:list.src;
        //   $('.username').innerHTML = list.account

        //   ================================================

        $(".user-introduction").innerHTML = `${
          list.introduction == null ? "无" : str1(list.introduction)
        } +<button class="spread">展开</button>`;
        console.log($(".spread"));
        $(".spread").onclick = function () {
          $(".h3").innerHTML = "介绍";
          $(".user-box").style.display = "none";
          $(".introduction-box").style.display = "block";
          $(".form-introduction").innerHTML = list.introduction;
          $(".back-introduction").onclick = function () {
            $(".user-box").style.display = "block";
            $(".introduction-box").style.display = "none";
          };
        };
        $(".user-introduction").innerHTML = `${
          list.introduction == null ? "无" : str1(list.introduction)
        }`;
        $(".user-account").innerHTML =
          list.account == null ? "无" : list.account;
        $(".user-nickname").innerHTML =
          list.nickname == null ? "无" : list.nickname;
        $(".user-age").innerHTML = list.age == null ? "无" : list.age;
        $(".user-email").innerHTML = list.email == null ? "无" : list.email;
        if (list.vip == 1) {
          $(".user-vip").innerHTML = "会员";
        } else if (list.vip == 0) {
          $(".user-vip").innerHTML = "普通用户";
        } else {
          $(".user-vip").innerHTML = "管理员";
        }
        $(".user-sex").innerHTML = list.sex == null ? "无" : list.sex;
        $(".user-signInPoint").innerHTML =
          list.signInPoint == null ? "无" : list.signInPoint;
        $(".user-vipTime").innerHTML =
          list.vipTime == null
            ? "无"
            : Math.floor(list.vipTime / 60 / 60 / 24) + "天";
      })
      .catch((err) => {
        console.log(err);
      });
  }

  // 模糊查询
  function searchdata(a, b) {
    var search_input = document.querySelector("#search");
    axios({
      method: "get",
      url: "/user/findUserByAccountLikeAndNickNameLike",
      params: {
        nickname: search_input.value,
        account: search_input.value,
        pageNow: a,
        pageSize: b,
      },
    })
      .then(function (data) {
        if (data.data.data.object.object.list.length == 0) {
          $("#search").value = "";
          $(".pageSize1").style.display = "none";
          $(".pageSize").style.display = "";
          $(".nowpage-btn-2").style.display = "none";
          $(".nowpage-btn-1").style.display = "";
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-exclamation-circle" style="color: rgb(255, 187, 0);" aria-hidden="true"></i>抱歉找不到`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 1500);
        } else {
          $("tbody").innerHTML = "";
          $(".pageye").innerHTML = "";
          $(".pageSize1").style.display = "";
          $(".pageSize").style.display = "none";
          $(".nowpage-btn-2").style.display = "";
          $(".nowpage-btn-1").style.display = "none";
          searchlist(data, searchdata);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }
  //  点击搜索按钮
  $(".search-btn").addEventListener("click", function () {
    $(".nowpage-1").innerHTML = 1;
    $(".nowpage").value = $(".nowpage-1").innerHTML;
    var search_input = document.querySelector("#search");
    if (search_input.value == "") {
      $(
        ".not"
      ).innerHTML = `<i class="fa fa-exclamation-circle" style="color: rgb(255, 187, 0);" aria-hidden="true"></i>抱歉找不到`;
      $(".not").style.display = "";
      setTimeout(() => {
        $(".not").style.display = "none";
      }, 1500);
    } else {
      $(
        ".not"
      ).innerHTML = `<i class="fa fa-check" aria-hidden="true" style="color:green"></i>搜索成功`;
      $(".not").style.display = "";
      setTimeout(() => {
        $(".not").style.display = "none";
      }, 1500);
      searchdata(1, $(".pageSize").value);
    }
  });
  // // 分页数据
  function list(data, b) {
    let list = data.data.data.object.list;
    let pageNow = data.data.data.object.pageNow;
    for (let i = 0; i < list.length; i++) {
      let vip;
      if (list[i].vip == 1) {
        vip = "会员";
      } else if (list[i].vip == 0) {
        vip = "普通用户";
      } else {
        vip = "管理员";
      }
      $("tbody").innerHTML += ` <tr>
        <td>${i + 1 + (pageNow - 1) * $(".pageSize").value}</td>
        <td><img src="${
          list[i].src == "未上传" ? "#" : list[i].src
        }" style="width:40px;height:40px;border-radius: 50%;"></img></td>
        <td>${list[i].account == null ? "无" : list[i].account}</td>
        <td>${list[i].nickname == null ? "无" : list[i].nickname}</td>
        <td>${list[i].email == null ? "无" : list[i].email}</td>
        <td>${vip}</td>
        <td>${list[i].videoNumber == null ? "无" : list[i].videoNumber}</td>
        <td><button class="usermessage">详情</button><button class="upvip">vip</button><button class="up">升级</button><button class="down">降级</button><button class='delete-user'><i class="fa fa-trash-o" aria-hidden="true"></i> 删除</button></td>
    </tr>`;
    }
    var tbr = tbody.querySelectorAll("tr");
    console.log(tbr);
    for (let i = 0; i < tbr.length; i++) {
      if (i % 2 == 0) {
        tbr[i].style.backgroundColor = "rgb(220, 220, 220)";
        tbr[i].onmouseover = function () {
          this.style.backgroundColor = "rgb(202,170,145)";
        };
        tbr[i].onmouseout = function () {
          this.style.backgroundColor = "rgb(220, 220, 220)";
        };
      }
    }
    // 详情按钮
    var usermessage_btn = document.querySelectorAll(".usermessage");
    console.log(usermessage_btn);
    for (let i = 0; i < usermessage_btn.length; i++) {
      popup(usermessage_btn[i], $(".user-box"), $(".back0"));
      usermessage_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        usermessage(userId);
      };
    }
    // 删除按钮绑定
    var del_btn = document.querySelectorAll(".delete-user");
    for (let i = 0; i < del_btn.length; i++) {
      del_btn[i].onclick = function () {
        var x = 2;
        if ((x = 2)) {
          console.log(x);
          $(".form-pop").querySelector("p").innerHTML = "你确定要删除吗？";
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            var userId = list[i].userId;
            delete_user(userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }
    //  修改按钮绑定
    var modify_btn = document.querySelectorAll(".modify-btn");
    for (let i = 0; i < modify_btn.length; i++) {
      popup(modify_btn[i], $(".modify-box"), $(".back1"));
      modify_btn[i].onclick = function () {
        console.log(list[i].account);
        $(".age1").value = list[i].age == null ? "" : list[i].age;
        if (list[i].birthday == (null || "无")) {
          $(".year").value = "";
          $(".month").value = "";
          $(".date").value = "";
        } else {
          let birthday = list[i].birthday;
          $(".year").value = str(0, 4, birthday);
          $(".month").value = str(5, 7, birthday);
          $(".date").value = str(8, 10, birthday);
        }
        $(".email1").value = list[i].email;
        $(".nickname1").value =
          list[i].nickname == null ? "无" : list[i].nickname;
        $(".password1").value = list[i].password;
        $(".sex1").value = list[i].sex == null ? "无" : list[i].sex;
        var account = list[i].account;
        updatauser(account, fenye);
      };
    }
    // 将用户降级
    var down_btn = document.querySelectorAll(".down");
    for (let i = 0; i < down_btn.length; i++) {
      if (list[i].vip == 0) {
        down_btn[i].disabled = true;
        down_btn[i].style.color = "rgb(80, 80, 80)";
        down_btn[i].style.cursor = "not-allowed";
      } else if (list[i].vip == 1) {
        down_btn[i].disabled = true;
        down_btn[i].style.color = "rgb(80, 80, 80)";
        down_btn[i].style.cursor = "not-allowed";
      }
      down_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        var x = 3;
        if ((x = 3)) {
          console.log(x);
          $(".pop-box-all").style.height = "250px";
          $(".form-pop").querySelector(
            "p"
          ).innerHTML = `高级密码:  <input type='text' class="password">`;
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            downuser($(".password").value, userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }
    // 将用户降级
    var up_btn = document.querySelectorAll(".up");
    for (let i = 0; i < up_btn.length; i++) {
      if (list[i].vip == 2) {
        up_btn[i].style.color = "rgb(80, 80, 80)";
        up_btn[i].disabled = true;
        up_btn[i].style.cursor = "not-allowed";
      }
      up_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        var x = 4;
        if ((x = 4)) {
          console.log(x);
          $(".pop-box-all").style.height = "250px";
          $(".form-pop").querySelector(
            "p"
          ).innerHTML = `高级密码:  <input type='text' class="password">`;
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            upuser($(".password").value, userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }

    // 将用户升为vip，定时间
    var upvip_btn = document.querySelectorAll(".upvip");
    for (let i = 0; i < upvip_btn.length; i++) {
      upvip_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        var x = 5;
        if ((x = 5)) {
          console.log(x);
          $(".pop-box-all").style.height = "270px";
          $(".form-pop").querySelector(
            "p"
          ).innerHTML = `高级密码:  <input type='text' class="password"><br>
          时长:  <input type='text' class="time">`;
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            upuservip($(".password").value, $(".time").value, userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }
    //  分页的总量
    var pageTotal = data.data.data.object.pageTotal;
    var pageTotalCount = data.data.data.object.pageTotalCount;

    // 跳转按钮
    $(".nowpage").value = $(".nowpage-1").innerHTML;
    $(".nowpage-btn-1").onclick = function () {
      $(".nowpage-1").innerHTML =
        $(".nowpage").value > pageTotal ? pageTotal : $(".nowpage").value;
      fenye($(".nowpage-1").innerHTML, $(".pageSize").value);
    };
    // $(".nowpage-btn-2").onclick = function () {
    //   searchdata($(".nowpage").value, $(".pageSize").value);
    // };
    $(".total").innerHTML = `共${pageTotal}页共${pageTotalCount}条数据`;
    if (pageTotal < 3) {
      for (let i = 0; i < pageTotal; i++) {
        let a = ` <a href="JavaScript:;" class='pagebtn'>${i + 1}</a>`;
        $(".pageye").insertAdjacentHTML("beforeend", a);
      }
    } else {
      for (let i = 0; i < 3; i++) {
        let a = ` <a href="JavaScript:;" class='pagebtn'>${i + 1}</a>`;
        $(".pageye").insertAdjacentHTML("beforeend", a);
      }
      var pagebtnAll = document.querySelectorAll(".pagebtn");
      if ($(".nowpage").value >= 3) {
        let c = $(".nowpage").value;
        let a = c >= pageTotal - 1 ? (c = pageTotal - 1) : c;
        pagebtnAll[0].innerHTML = a - 1;
        pagebtnAll[1].innerHTML = a;
        pagebtnAll[2].innerHTML = ++a;
      }
    }
    var pagebtnAll = document.querySelectorAll(".pagebtn");
    for (let i = 0; i < pagebtnAll.length; i++) {
      pagebtnAll[i].onclick = function () {
        b(this.innerHTML, $(".pageSize").value);
        $(".nowpage-1").innerHTML = `${this.innerHTML}`;
        $(".nowpage").value = $(".nowpage-1").innerHTML;
      };
      if (pagebtnAll[i].innerHTML == $(".nowpage-1").innerHTML) {
        pagebtnAll[i].style.backgroundColor = "rgb(202,170,145)";
      } else if (pagebtnAll[i].innerHTML == $(".nowpage-1").innerHTML) {
        for (let j = 0; j < pagebtnAll.length; j++) {
          pagebtnAll[j].style.backgroundColor = "";
        }
        pagebtnAll[i].style.backgroundColor = "rgb(202,170,145)";
      }
    }
    $("#next").onclick = function () {
      var x = $(".nowpage-1").innerHTML;
      x++;
      var y = x >= pageTotal ? (x = pageTotal) : x;
      $(".nowpage-1").innerHTML = `${y}`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b($(".nowpage-1").innerHTML, $(".pageSize").value);
      console.log($(".nowpage-1").innerHTML, $(".nowpage").value);
      console.log($(".nowpage").value);
    };
    $("#pre").onclick = function () {
      var x = $(".nowpage-1").innerHTML;
      x--;
      var y = x <= 1 ? (x = 1) : x;
      $(".nowpage-1").innerHTML = `${y}`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b($(".nowpage-1").innerHTML, $(".pageSize").value);
    };
    $(".frist").onclick = function () {
      $(".nowpage-1").innerHTML = `1`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b(1, $(".pageSize").value);
    };
    $(".last").onclick = function () {
      $(".nowpage-1").innerHTML = `${pageTotal}`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b(pageTotal, $(".pageSize").value);
    };
  }
  // // 搜索数据
  function searchlist(data, b) {
    let list = data.data.data.object.object.list;
    let pageNow = data.data.data.object.object.pageNow;
    for (let i = 0; i < list.length; i++) {
      let vip;
      if (list[i].vip == 1) {
        vip = "会员";
      } else if (list[i].vip == 0) {
        vip = "普通用户";
      } else {
        vip = "管理员";
      }
      $("tbody").innerHTML += ` <tr>
        <td>${i + 1 + (pageNow - 1) * $(".pageSize").value}</td>
        <td><img src="${
          list[i].src == "未上传" ? "#" : list[i].src
        }" style="width:40px;height:40px;border-radius: 50%;"></img></td>
        <td>${list[i].account == null ? "无" : list[i].account}</td>
        <td>${list[i].nickname == null ? "无" : list[i].nickname}</td>
        <td>${list[i].email == null ? "无" : list[i].email}</td>
        <td>${vip}</td>
        <td>${list[i].videoNumber == null ? "无" : list[i].videoNumber}</td>
        <td><button class="usermessage">详情</button><button class="upvip">vip</button><button class="up">升级</button><button class="down">降级</button><button class='delete-user'><i class="fa fa-trash-o" aria-hidden="true"></i> 删除</button></td>
    </tr>`;
      var tbr = tbody.querySelectorAll("tr");
      if (i % 2 == 0) {
        tbr[i].style.backgroundColor = "rgb(220, 220, 220)";
        tbr[i].onmouseover = function () {
          this.style.backgroundColor = "rgb(202, 170, 145)";
        };
        tbr[i].onmouseout = function () {
          this.style.backgroundColor = "rgb(220, 220, 220)";
        };
      }
    }
    // 详情按钮
    var usermessage_btn = document.querySelectorAll(".usermessage");
    console.log(usermessage_btn);
    for (let i = 0; i < usermessage_btn.length; i++) {
      popup(usermessage_btn[i], $(".user-box"), $(".back0"));
      usermessage_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        usermessage(userId);
      };
    }
    // 删除按钮绑定
    var del_btn = document.querySelectorAll(".delete-user");
    for (let i = 0; i < del_btn.length; i++) {
      del_btn[i].onclick = function () {
        var x = 2;
        if ((x = 2)) {
          console.log(x);
          $(".form-pop").querySelector("p").innerHTML = "你确定要删除吗？";
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            var userId = list[i].userId;
            delete_user(userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }
    // 将用户降级
    var down_btn = document.querySelectorAll(".down");
    for (let i = 0; i < down_btn.length; i++) {
      if (list[i].vip == 0) {
        down_btn[i].disabled = true;
        down_btn[i].style.color = "rgb(80, 80, 80)";
        down_btn[i].style.cursor = "not-allowed";
      } else if (list[i].vip == 1) {
        down_btn[i].disabled = true;
        down_btn[i].style.color = "rgb(80, 80, 80)";
        down_btn[i].style.cursor = "not-allowed";
      }
      down_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        var x = 3;
        if ((x = 3)) {
          console.log(x);
          $(".form-pop").querySelector(
            "p"
          ).innerHTML = `高级密码: <input type='text' class="password">`;
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            downuser($(".password").value, userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }
    // 将用户降级
    var up_btn = document.querySelectorAll(".up");
    for (let i = 0; i < up_btn.length; i++) {
      if (list[i].vip == 2) {
        up_btn[i].style.color = "rgb(80, 80, 80)";
        up_btn[i].disabled = true;
        up_btn[i].style.cursor = "not-allowed";
      }
      up_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        var x = 4;
        if ((x = 4)) {
          console.log(x);
          $(".form-pop").querySelector(
            "p"
          ).innerHTML = `高级密码: <input type='text' class="password">`;
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            upuser($(".password").value, userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }

    // 将用户升为vip，定时间
    var upvip_btn = document.querySelectorAll(".upvip");
    for (let i = 0; i < upvip_btn.length; i++) {
      upvip_btn[i].onclick = function () {
        var userId = list[i].userId;
        console.log(userId);
        var x = 5;
        if ((x = 5)) {
          console.log(x);
          $(".pop-box-all").style.height = "270px";
          $(".form-pop").querySelector(
            "p"
          ).innerHTML = `高级密码:  <input type='text' class="password"><br>
           时长:  <input type='text' class="time">`;
          $(".pop-box").style.display = "block";
          $(".submit-pop1").onclick = function () {
            upuservip($(".password").value, $(".time").value, userId, b);
            $(".pop-box").style.display = "none";
          };
          $(".submit-pop2").onclick = function () {
            $(".pop-box").style.display = "none";
          };
          $(".back-pop").onclick = function () {
            $(".pop-box").style.display = "none";
          };
        }
      };
    }
    //  修改按钮绑定
    // var modify_btn = document.querySelectorAll('.modify-btn');
    // for(let i = 0 ;i<modify_btn.length; i++){
    // popup(modify_btn[i],$(".modify-box"),$(".back1"));
    //  modify_btn[i].onclick=function(){
    //      console.log(list[i].account);
    //     $(".age1").value =list[i].age==null?'':list[i].age;
    //     // if(list[i].birthday==(null||'无')){
    //     //     $('.year').value='';
    //     //     $('.month').value='';
    //     //     $('.date').value='';
    //     // }else{
    //     //     // let birthday1 = list[i].birthday
    //     //     // $('.year').value=str(0,4,birthday1);
    //     //     // $('.month').value=str(5,7,birthday1);
    //     //     // $('.date').value=str(8,10,birthday1);
    //     // }
    //     $(".email1").value =list[i].email
    //     $(".nickname1").value =list[i].nickname==null?'无':list[i].nickname;
    //     $(".password1").value =list[i].password;
    //     $(".sex1").value =list[i].sex==null?'无':list[i].sex;
    //     var account =list[i].account;
    //     updatauser(account,searchdata);
    //  }
    //  }
    //  分页的总量
    var pageTotal = data.data.data.object.object.pageTotal;
    var pageTotalCount = data.data.data.object.object.pageTotalCount;

    // 跳转按钮
    $(".nowpage").value = $(".nowpage-1").innerHTML;
    $(".nowpage-btn-2").onclick = function () {
      $(".nowpage-1").innerHTML =
        $(".nowpage").value > pageTotal ? pageTotal : $(".nowpage").value;
      searchdata($(".nowpage-1").innerHTML, $(".pageSize").value);
    };

    $(".total").innerHTML = `共${pageTotal}页共${pageTotalCount}条数据`;
    if (pageTotal < 3) {
      for (let i = 0; i < pageTotal; i++) {
        let a = ` <a href="JavaScript:;" class='pagebtn'>${i + 1}</a>`;
        $(".pageye").insertAdjacentHTML("beforeend", a);
      }
    } else {
      for (let i = 0; i < 3; i++) {
        let a = ` <a href="JavaScript:;" class='pagebtn'>${i + 1}</a>`;
        $(".pageye").insertAdjacentHTML("beforeend", a);
      }
      var pagebtnAll = document.querySelectorAll(".pagebtn");
      if ($(".nowpage").value >= 3) {
        let c = $(".nowpage").value;
        let a = c >= pageTotal - 1 ? (c = pageTotal - 1) : c;
        pagebtnAll[0].innerHTML = a - 1;
        pagebtnAll[1].innerHTML = a;
        pagebtnAll[2].innerHTML = ++a;
      }
    }
    var pagebtnAll = document.querySelectorAll(".pagebtn");
    for (let i = 0; i < pagebtnAll.length; i++) {
      pagebtnAll[i].onclick = function () {
        b(this.innerHTML, $(".pageSize").value);
        $(".nowpage-1").innerHTML = `${this.innerHTML}`;
        $(".nowpage").value = $(".nowpage-1").innerHTML;
      };
      if (pagebtnAll[i].innerHTML == $(".nowpage-1").innerHTML) {
        pagebtnAll[i].style.backgroundColor = "rgb(202,170,145)";
      } else if (pagebtnAll[i].innerHTML == $(".nowpage").value) {
        for (let j = 0; j < pagebtnAll.length; j++) {
          pagebtnAll[j].style.backgroundColor = "";
        }
        pagebtnAll[i].style.backgroundColor = "rgb(202,170,145)";
      }
    }
    $("#next").onclick = function () {
      var x = $(".nowpage-1").innerHTML;
      x++;
      var y = x >= pageTotal ? (x = pageTotal) : x;
      $(".nowpage-1").innerHTML = `${y}`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b($(".nowpage-1").innerHTML, $(".pageSize").value);
      console.log($(".nowpage-1").innerHTML, $(".nowpage").value);
      console.log($(".nowpage").value);
    };
    $("#pre").onclick = function () {
      var x = $(".nowpage-1").innerHTML;
      x--;
      var y = x <= 1 ? (x = 1) : x;
      $(".nowpage-1").innerHTML = `${y}`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b($(".nowpage-1").innerHTML, $(".pageSize").value);
    };
    $(".frist").onclick = function () {
      $(".nowpage-1").innerHTML = `1`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b(1, $(".pageSize").value);
    };
    $(".last").onclick = function () {
      $(".nowpage-1").innerHTML = `${pageTotal}`;
      $(".nowpage").value = $(".nowpage-1").innerHTML;
      b(pageTotal, $(".pageSize").value);
    };
  }

  // // 添加用户
  (function () {
    let accountreg = /^[a-z0-9_-]{6,16}$/;
    $(".submit").addEventListener("click", function () {
      if (accountreg.test($(".account").value)) {
        axios({
          method: "post",
          url: "/user/addUser",
          params: {
            account: $(".account").value,
            password: $(".password").value,
            nickname: $(".nickname").value,
          },
        })
          .then(function (data) {
            var object = data.data.data.object;
            if (object === "添加成功") {
              $(
                ".not"
              ).innerHTML = `<i class="fa fa-check-circle" style="color:green;" aria-hidden="true"></i></i>添加成功`;
              $(".not").style.display = "";
              setTimeout(() => {
                $(".not").style.display = "none";
              }, 2000);
              $(".add-box").style.display = "none";
              fenye($(".nowpage-1").innerHTML, $(".pageSize").value);
            } else {
              alert("添加失败");
              $(".add-box").style.display = "none";
            }
          })
          .catch((err) => {
            console.log(err);
          });
      } else {
        alert("账号格式不正确");
      }
    });
  })();

  //  // 修改用户数据
  // function updatauser(account,b){
  //     let emailreg =/^[0-9-A-Za-zd]+([-_.][0-9-A-Za-zd]+)*@([0-9-A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;
  //     $(".submit1").onclick=function(){
  //         if(emailreg.test($(".email1").value)||$(".email1").value==''){
  //     axios({
  //         method: 'put',
  //         url: '/user/updateUsers',
  //         params:{
  //             account:account,
  //             age:$(".age1").value,
  //             birthday:$(".year").value+'-'+$('.month').value+'-'+$('.date').value,
  //             email:$(".email1").value==''?null:$(".email1").value,
  //             nickname:$(".nickname1").value,
  //             password:$(".password1").value,
  //             sex:$(".sex1").value
  //         }
  //     }).then(function(data){
  //         let data1=data.data.data
  //         if(data1.message =='修改成功'){
  //      $('.not').innerHTML=`<i class="fa fa-check-circle" style="color:green;" aria-hidden="true"></i></i>修改成功`;
  //         $('.not').style.display=''
  //         setTimeout(() => {
  //            $('.not').style.display='none'
  //        }, 2000);
  //         $(".modify-box").style.display='none';
  //         b($('.nowpage-1').innerHTML,$('.pageSize').value);
  //         }else{
  //             alert(data1.message);
  //         }

  //     }).catch(err=>{
  //         console.log(err);
  //     })
  // }else if(!(emailreg.test($(".email1").value)||$(".email1").value=='')){
  // alert('邮箱格式不对')
  // }
  // }
  // }

  // 将用户降为用户
  function downuser(password, userId, b) {
    axios({
      method: "put",
      url: "/user/demotionUserVip",
      params: {
        password: password,
        userId: userId,
      },
    })
      .then(function (data) {
        if (data.data.data.message == "高级密码不对,请重新输入") {
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-times" aria-hidden="true" style="color:red;"></i> 高级密码不对,请重新输入`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 2000);
        } else {
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-check-circle" style="color:green;" aria-hidden="true"></i>升级成功`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 2000);
          b($(".nowpage-1").innerHTML, $(".pageSize").value);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }
  // 将用户升级管理员
  function upuser(password, userId, b) {
    axios({
      method: "put",
      url: "  /user/upgradeUserVip",
      params: {
        password: password,
        userId: userId,
      },
    })
      .then(function (data) {
        if (data.data.data.message == "高级密码不对,请重新输入") {
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-times" aria-hidden="true" style="color:red;"></i> 高级密码不对,请重新输入`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 2000);
        } else {
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-check-circle" style="color:green;" aria-hidden="true"></i>升级成功`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 2000);
          b($(".nowpage-1").innerHTML, $(".pageSize").value);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }

  // 将用户升级管理员
  function upuservip(password, time, userId, b) {
    axios({
      method: "put",
      url: "/user/upgradeUserVipAndTime",
      params: {
        password: password,
        time: time,
        userId: userId,
      },
    })
      .then(function (data) {
        if (data.data.data.message == "高级密码不对,请重新输入") {
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-times" aria-hidden="true" style="color:red;"></i> 高级密码不对,请重新输入`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 2000);
        } else {
          $(
            ".not"
          ).innerHTML = `<i class="fa fa-check-circle" style="color:green;" aria-hidden="true"></i>升级成功`;
          $(".not").style.display = "";
          setTimeout(() => {
            $(".not").style.display = "none";
          }, 2000);
          b($(".nowpage-1").innerHTML, $(".pageSize").value);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }
};
